package com.qf.service.impl;

import com.qf.entity.GoodsSku;
import com.qf.entity.MallGoods;
import com.qf.entity.MallGoodsSku;
import com.qf.mapper.GoodsSkuMapper;
import com.qf.service.IGoodSkuService;
import com.qf.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
    作者：Administrator
    时间：2021/9/27 0027 17:15
* */
@Service
public class GoodsSkuService implements IGoodSkuService {
    @Autowired
    private GoodsSkuMapper goodsSkuMapper;
    @Override
    public Result saveSku(GoodsSku goodsSku) {
        MallGoods mallGoods = goodsSku.getGoods();
        List<MallGoodsSku> mallGoodsSkuList = goodsSku.getSkus();
        int i = goodsSkuMapper.saveGoods(mallGoods);
        System.out.println(mallGoods.getSpuId());
        if( i!=0 ){
            for (MallGoodsSku mallGoodsSku : mallGoodsSkuList) {
                mallGoodsSku.setSpuId(mallGoods.getSpuId());
                mallGoodsSku.setSkuTitle(mallGoods.getGoodsName());
            }
            goodsSkuMapper.saveSkus(mallGoodsSkuList);

        }
        return new Result<>(true,"success");
    }

}
